/********************************************************************
 * File: uart.h
 * Description: Header file of AT89C52 serial port communication.
 * Version: v0.0
 * Date: 2024-5-21
 * Author: zhengxinyu13@qq.com
 * ---------- Revision History ----------
 * <version> <date> <author> <desc>
 * 
 ********************************************************************/

#ifndef __UART_H__
#define __UART_H__

#include "main.h"
#include <stdio.h>

/* System frequency */
#define FOSC 11059200UL		//The crystal frequency is 11.0592MHz.

/* System clock */
#define _1T_MODEL   1		//No frequency division mode.
#define _12T_MODEL  12		//12 frequency division mode.

#define SYSCLK 32

/* List of baud rates */
#define BAUD_RATE_1200	1200
#define BAUD_RATE_2400	2400
#define BAUD_RATE_4800	4800
#define BAUD_RATE_9600	9600
#define BAUD_RATE_19200	19200

#define END_MARK 		'`'	//User defined.
#define UART_BUF_SIZE 	64	//UART buffer size.

/* Define UART parity mode */
typedef enum {
	NONE_PARITY,
	ODD_PARITY,
	EVEN_PARITY,
	MARK_PARITY,
	SPACE_PARITY
} PARITYBIT;

typedef struct
{
	uint8_t buff[UART_BUF_SIZE];
	uint8_t flag;
	uint8_t len;
} UART_REC;

extern UART_REC uart_rec;

typedef enum {
    UART_IRP_DISABLE,
    UART_IRP_ENABLE
} UART_IRP;

void uart_init(uint16_t baudrate, UART_IRP irp_enable, PARITYBIT paritybit);
void send_byte(uint8_t data_byte);
void send_string(uint8_t *data_string);

#endif // __UART_H__